package triggerhelper.dataHolders;

import java.io.Serializable;
import java.util.ArrayList;
import javax.swing.DefaultListModel;

public class TriggerProject implements Serializable {

    //instance variables
    private static final long serialVersionUID = 1L;
    private String name, projectFileName;
    private ArrayList<SimpleTrigger> triggers;
    private boolean isSaved = false, isFileSaved = false;

    //constructors
    public TriggerProject(String name_) {
        name = name_;
        triggers = new ArrayList<SimpleTrigger>();
    }
    public TriggerProject(TriggerProject a) {
        isSaved = a.isSaved();
        isFileSaved = a.isFileSaved();
        name = a.getName();
        projectFileName = a.getProjectFileName();
        triggers = new ArrayList<SimpleTrigger>(a.getTriggers());
    }

    // <editor-fold defaultstate="collapsed" desc="Getter methods">
    public boolean hasTriggers() {
        return !triggers.isEmpty();
    }

    public String getName() {
        return name;
    }

    public ArrayList<SimpleTrigger> getTriggers() {
        return triggers;
    }

    public String getProjectFileName() {
        return projectFileName;
    }

    public boolean isSaved() {
        return isSaved;
    }

    public boolean isFileSaved() {
        return isFileSaved;
    }

    public SimpleTrigger getFirstTrigger() {
        return triggers.get(0);
    }

    public String getFirstTriggerName() {
        return triggers.get(0).getName();
    }// </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Setter methods">
    public void setSaved(boolean b) {
        isSaved = b;
    }
    public void fileSave() {
        isFileSaved = true;
    }
    public void setTriggers(ArrayList<SimpleTrigger> triggers_) {
        triggers = new ArrayList(triggers_);
    }
    public void saveTriggers(DefaultListModel listModel) {
        ArrayList<SimpleTrigger> tempList = new ArrayList<SimpleTrigger>();
        for (int i=0; i<listModel.size(); i++) {
            SimpleTrigger t = (SimpleTrigger)listModel.get(i);
            t.setSaved(true);
            tempList.add(t);
        }
        setTriggers(tempList);
        isSaved = true;
    }
    public void setProjectFileName(String s) {
        projectFileName = s;
    }// </editor-fold>
}
